home *** CD-ROM | disk | FTP | other *** search
- Path: news.crd.ge.com!rebecca!rpi!not-for-mail
- From: danm@zipnet.net (Dan Muller)
- Newsgroups: comp.lang.c++,comp.lang.c++.moderated,comp.object
- Subject: Re: C++ objects in shared memory
- Date: 9 Apr 1996 08:41:21 -0000
- Organization: ZIPNET.NET - The NorthEast US's premier ISP
- Sender: cppmods@netlab.cs.rpi.edu
- Approved: devitto@ferndown.ate.slb.com
- Message-ID: <4kd7rh$m2a@netlab.cs.rpi.edu>
- References: <4jtte3$5ng@netlab.cs.rpi.edu>
- NNTP-Posting-Host: netlab.cs.rpi.edu
- X-Original-Date: Fri, 05 Apr 1996 04:35:19 GMT
-
- Tony Confrey <ac11@gte.com> wrote:
-
- >I am trying to store instances of C++ objects in shared memory so
- >that their function and data members can be accessed by multiple
- >processes running on the same unix box.
-
- >Storing the instance in shared memory is no problem - I've been using
- >placement new with a previously allocated block of shared memory that
- >all processes connect to. Calling member functions, in particular
- >virtual member functions, is more difficult.
-
- >I'm finding (actually more like deducing) the following: If process
- >A creates an instance then the vtbl points to function addresses in
- >process A's address space. Calling non virtual functions or
- >accessing data members from another process, B, works fine.
- >However calling virtual functions from B segv's because its
- >trying to call outside its address space.
-
- >For a while it looked like linking the class library as a shared library
- >would work - in fact it does under aix - because the functions end up in
- >the same place in memory. However under solaris the address spaces are
- >mapped differently.
-
- >Any suggestion would be appreciated. Can this be done? Is there some
- >other approach I should take? I find it hard to believe that no
- >one has ever tried such a thing.
-
- Tony,
-
- The approach you're trying would be really nice if it worked, but as
- you're finding, it's not at all portable and may not work at all on
- some systems.
-
- You're probably better off using a proxy approach. In each process,
- create proxy objects that have the same interface as the "real"
- object.
-
- The real object could exist in one process, and the proxies could
- communicate with it via any number of methods. This is the basic idea
- used with most distributed object systems, where the real object might
- not even be on the same machine. RPC mechanisms are commonly used to
- communicate between proxies and the real object, because they can
- handle much of the marshalling/unmarshalling work easily.
-
- However, this might be overkill. In your case, the "real" object might
- just be a block of data in shared memory, and the proxies coordinate
- access to the data. You'll still have a problem with pointers, of
- course.
-
- This is very brief, but I hope this gives you some ideas.
-
- --
- Dan Muller
- danm@zipnet.net
-
-
- [ Articles to moderate: mailto:c++-submit@netlab.cs.rpi.edu ]
- [ Read the C++ FAQ: http://www.connobj.com/cpp/cppfaq.htm ]
- [ Moderation policy: http://www.connobj.com/cpp/guide.htm ]
- [ Comments? mailto:c++-request@netlab.cs.rpi.edu ]
-